package cn.bdqn.service.impl;


import cn.bdqn.domain.Teacher;
import cn.bdqn.mapper.TeacherMapper;
import cn.bdqn.service.TeacherService;
import cn.bdqn.utils.result.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 老师类业务实现
 * @author qq175
 */
@Service("teacherService")
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private TeacherMapper teacherMapper;
    /**
     * 根据id查询老师信息
     * @param id
     * @return
     */
    @Override
    public Teacher queryTeacherById(Integer id) {

        return teacherMapper.selectById(id);
    }
    /**
     * 添加老师信息
     * @param teacher
     * @return
     */
    @Override
    public void insert(Teacher teacher) {
        teacherMapper.insert(teacher);
    }
    /**
     * 修改老师信息
     * @param teacher
     * @return
     */
    @Override
    public int update(Teacher teacher) {
        return teacherMapper.updateById(teacher);
    }
    /**
     * 根据id逻辑删除老师信息
     * @param id
     * @return
     */
    @Override
    public void deleteById(Integer id) {
        teacherMapper.deleteById(id);
    }
    /**
     * 根据id发布老师信息
     * @param id
     * @return
     */
    @Override
    public void releaseById(Integer id) {
        teacherMapper.releaseById(id);
    }
    /**
     * 查询全部分页
     * @param startNumber
     * @return
     */
    @Override
    public Page queryAll(Integer startNumber, Integer pageSize) {
        //每页显示的数量
        //开启分页 pageNum > 0 ? pageNum:1 判断当前页数是否大于0
        PageHelper.startPage(startNumber > 0 ? startNumber:1,pageSize);
        //查询全部数据
        List<Teacher> teachers = teacherMapper.selectAll();
        //分页
        PageInfo<Teacher> teacherPageInfo = new PageInfo<Teacher>(teachers);
        //封装分页数据
        Page page = new Page();
        //分页之后的数据
        page.setMenuList(teacherPageInfo.getList());
        //总记录数
        page.setTotalRecord((int)teacherPageInfo.getTotal());
        //返回封装的分页对象
        return page;
    }

    /**
     * 根据baseId查询教师信息分页
     * @param baseId
     * @param startNumber
     * @return
     */
    @Override
    public Page queryByBaseId(Integer baseId, Integer startNumber, Integer pageSize) {
        //每页显示的数量
        //开启分页 pageNum > 0 ? pageNum:1 判断当前页数是否大于0
        PageHelper.startPage(startNumber > 0 ? startNumber:1,pageSize);
        //查询全部数据
        List<Teacher> teachers = teacherMapper.selectByBaseId(baseId);
        //分页
        PageInfo<Teacher> teacherPageInfo = new PageInfo<Teacher>(teachers);
        //封装分页数据
        Page page = new Page();
        //分页之后的数据
        page.setMenuList(teacherPageInfo.getList());
        //总记录数
        page.setTotalRecord((int)teacherPageInfo.getTotal());
        //返回封装的分页对象
        return page;
    }

    /**
     * 根据基地id查询步分页
     * @param baseId
     * @return
     */
    @Override
    public List<Teacher> queryByBase(Integer baseId) {
        return teacherMapper.selectByBase(baseId);
    }


}
